﻿#include "UIData.h"
#include "ModelData.h"

#include "DataCenter.h"

Data::Data()
{
}

Data::~Data()
{
}

DataCenter::DataCenter()
{
}

DataCenter::~DataCenter()
{
    for(auto x : m_UIDatas) delete x;
    m_UIDatas.clear();
    
    for(auto x : m_ModelDatas) delete x;
    m_ModelDatas.clear();
}

DataCenter& DataCenter::getInstance()
{
    // 局部静态特性的方式实现单例
    // c++11后，此方法不存在线程不安全问题
    static DataCenter instance;
    return instance;
}

UIData *DataCenter::GetUIData(const std::string &name)
{
    for(const auto& x : m_UIDatas)
        if(x->m_Name == name)
            return x;
    return nullptr;
}

ModelData *DataCenter::GetModelData(const std::string &name)
{
    for(const auto& x : m_ModelDatas)
        if(x->m_Name == name)
            return x;
    return nullptr;
}
